package com.reran.demo;

import java.util.concurrent.*;

/**
 * @description:
 * @author: WangSiTeng
 * @date: 2021/11/27
 */
public class ThreadDemo4 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ExecutorService executorService = Executors.newFixedThreadPool(2);

        for (int i = 0; i < 10; i++) {
            Future<Object> submit = executorService.submit(new CallableDemo());
            System.out.println(submit.get());
        }

        System.out.println("Exiting main Thread: " + Thread.currentThread().getName());

    }

    static class CallableDemo implements Callable<Object> {

        @Override
        public Object call() throws Exception {
            Object res = null;
            synchronized (this) {
                Thread.sleep(1000);
                res = Thread.currentThread().getName();
            }
            return res;
        }
    }
}
